package system

import (
	"admin.supervise.limaochuxing.top/admin/service/system"
	"admin.supervise.limaochuxing.top/core"
	"admin.supervise.limaochuxing.top/core/response"

	"github.com/gin-gonic/gin"
)

var CaptchaGroup = core.Group("/captcha", newCaptchaHandler, regCaptcha)

func newCaptchaHandler(srv system.ICaptchaService) *captchaHandler {
	return &captchaHandler{srv: srv}
}

func regCaptcha(rg *gin.RouterGroup, group *core.GroupBase) error {
	return group.Reg(func(handle *captchaHandler) {
		rg.GET("/generate", handle.generate)
	})
}

type captchaHandler struct {
	srv system.ICaptchaService
}

// generate 生成验证码
func (ch *captchaHandler) generate(c *gin.Context) {
	resp, err := ch.srv.Generate()
	response.CheckAndRespWithData(c, resp, err)
}
